
import java.util.Scanner;

public class 回文日期 {
    static int[] isLeapYear = {0,31,29,31,30,31,30,31,31,30,31,30,31};
    static int[] noLeapYear = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    public static void main(String[] args) {
        //error 不是一一枚举 |^_^|
       /* Scanner s = new Scanner(System.in);
        int l = s.nextInt();
        int r = s.nextInt();
       int count=0;
        for(int i=l;i<=r;i++) {
            String s1 = String.valueOf(i);
            String a = s1.substring(0,4);
            String b = s1.substring(4,8);
            StringBuilder b1= new StringBuilder(b);
            b1.reverse();
            if(a.equals(String.valueOf(b1))) count++;
        }
        System.out.println(count);*/
       Scanner s = new Scanner(System.in);
        int l = s.nextInt();
        int r = s.nextInt();
        int count = 0;
        for (int i = 1000; i <=9999 ; i++) {
            String s1 = i+"";
            s1+=reverse1(s1);
            int n = Integer.parseInt(s1);
            if(n>=l && n<=r) {

                int year = Integer.parseInt(s1.substring(0,4));
                int mouth = Integer.parseInt(s1.substring(4,6));
                int day = Integer.parseInt(s1.substring(6,8));
                if(isCalendar(year,mouth,day)){
                    count++;
                    System.out.println(s1);
                }
            }
        }
        System.out.println(count);

    }
    private static boolean isCalendar(int year,int mouth,int day) {
        if((year%100!=0 && year%4==0)  || year%400==0) {
            if(mouth<=12 && day<=isLeapYear[mouth] ) return true;
            return false;
        }
        else {
            if(mouth<=12 && day<=noLeapYear[mouth] ) return true;
            return false;
        }

    }
    public static String reverse1(String str) {
        return new StringBuilder(str).reverse().toString();
    }

}
